package comp512.classes;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class Message implements Serializable {
	private static final long serialVersionUID = 1L;
	private String flag;
	Player player;
	private String message;

	public Message(String flag, Player player, String message) {
		this.flag = flag;
		this.player = player;
		this.message = message;
	}

	public Message(Message message) {
		this.flag = message.getFlag();
		this.player = message.getPlayer();
		this.message = message.getMessage();
	}

	private void writeObject(java.io.ObjectOutputStream oos) throws IOException {
		oos.writeObject(flag);
		oos.writeObject(message);
		oos.writeObject(player);
	}

	private void readObject(java.io.ObjectInputStream ois) throws ClassNotFoundException, IOException {
		flag = (String) ois.readObject();
		message = (String) ois.readObject();
		player = (Player) ois.readObject();
	}

	// getters
	public String getFlag() {
		return flag;
	}

	public Player getPlayer() {
		return Player.getInstance();
	}

	public String getMessage() {
		return message;
	}

	// setters
	public void setFlag(String flag) {
		this.flag = flag;
	}

	public void setPlayer(Player player) {
		Player.setPlayerInstance(player);
		this.player = Player.getInstance();
	}

	public void setMessage(String message) {
		this.message = message;
	}
	
	@Override
	public String toString() {
		return this.getMessage();
	}
}
